package org.springblade.common.security.service;

import lombok.SneakyThrows;
import org.springblade.common.constant.SecurityConstants;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;

import javax.sql.DataSource;

/**
 * @File: CsjClientDetailsService.java
 * @Project: csjbot-service
 * @Package: org.springblade.auth.service
 * @Description:
 * @Company: 苏州穿山甲机器人股份有限公司
 * @author: zhouhong
 * @date: 2019年11月21 11时22分
 * @version: V1.0.0
 */
public class CsjClientDetailsService extends JdbcClientDetailsService {
	public CsjClientDetailsService(DataSource dataSource) {
		super(dataSource);
	}

	/**
	 * 重写原生方法支持redis缓存
	 *
	 * @param clientId
	 * @return
	 */
	@Override
	@SneakyThrows
	@Cacheable(value = SecurityConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null")
	public ClientDetails loadClientByClientId(String clientId) {
		return super.loadClientByClientId(clientId);
	}
}
